/**
 * Copyright (C) 2021 - 2031 O-Cubes Co., Ltd.
 */

/****************************************************************
 *  @file    trap.c
 *  @brief   The trap process
 *  @version v1.0
 *  @date    03. Apr. 2023
 ****************************************************************/

#include <stdint.h>

#include "core.h"
#include "printf.h"

void (*trap_c_callback)(void);
uint32_t  trapcnt = 0;
void trap_c(uint32_t ulMcause)
{
	printf("CPU Exception: NO.%ld\r\n", ulMcause & 0x3FF);
	printf("mepc   : %08lx\r\n", __get_MEPC());
	printf("mstatus: %08lx\r\n", __get_MSTATUS());

	if (trap_c_callback) {
		trap_c_callback();
	}

	while (1)
	{
		trapcnt++;
		if(trapcnt>1000000000) break;
	}
}

